﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data;

namespace OnlineDovizOtomasyonu
{
    public partial class Default : System.Web.UI.Page
    {
        Fonksiyon Sistem = new Fonksiyon();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnGiris_Click(object sender, EventArgs e)
        {
            GirisKontrol();
        }

        void GirisKontrol()
        {
           
            SqlConnection Mycon = Sistem.baglan();
            SqlDataAdapter MyAdp = new SqlDataAdapter("SELECT * FROM TBLKULLANICI WHERE KULLANICI='" + String.Format("{0}", Request.Form["username"]) + "' AND SIFRE='" + String.Format("{0}", Request.Form["password"]) + "'", Mycon);
            DataTable MyTable = new DataTable();
            MyAdp.Fill(MyTable);
            if (MyTable.Rows.Count == 0)
            {
                Response.Write("<script>alert('Girilen Kullanıcı  Adınız veya Şifreniz Yanlıştır!')</script>");
            }
            else
            {
                SqlConnection con = Sistem.baglan();
                SqlCommand komut = new SqlCommand();
                komut.Connection = con;
                komut.CommandText = "SELECT * FROM TBLKULLANICI WHERE KULLANICI='" + String.Format("{0}", Request.Form["username"]) + "' AND SIFRE='" + String.Format("{0}", Request.Form["password"]) + "'";
                SqlDataReader dr = komut.ExecuteReader();
                while (dr.Read())
                {
                    Session["webingAdminID"] = dr["ID"].ToString();
                    Response.Redirect("sistem.aspx");
                }
            }

        }

       
    }
}